/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fatec.ads.bo;

import br.edu.fatec.ads.classes.LocalPK;
import br.edu.fatec.ads.classes.Predio;
import br.edu.fatec.ads.dao.HibernateGenericDAO;
import br.edu.fatec.ads.util.ComboBoxItem;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;

/**
 *
 * @author Ubirajara
 */
public class BusinessObjectPredio implements IBusinessObject {

    private HibernateGenericDAO dao = null;

    public BusinessObjectPredio(){
        dao = new HibernateGenericDAO(Predio.class);
    }

    public void beginTransaction() {
        dao.beginTransaction();
    }

    public void commitTransaction() {
        dao.commitTransaction();
    }

    public void rollbackTransaction() {
        dao.rollbackTransaction();
    }

    public void clearSession() {
        dao.clearSession();
    }

    public Predio recuperarPredioPorId(Integer id){
        Predio predio = new Predio(id);

        try{
            predio = (Predio) dao.get(predio.getPK());
        }catch(HibernateException cause){
            cause.printStackTrace();
        }

        return predio;
    }

    public List<ComboBoxItem> recuperarListaPredios(){
        List<Predio> prediosEncontrados = null;
        List<ComboBoxItem> comboBoxPredios = new ArrayList<ComboBoxItem>();

        prediosEncontrados = dao.findByCriterion(null);

        if(prediosEncontrados != null && !prediosEncontrados.isEmpty()){
            for (Predio predio : prediosEncontrados) {
                comboBoxPredios.add(new ComboBoxItem(predio.getCodigo(), predio.getNome()));
            }
        }
        
        return comboBoxPredios;
    }

}